/**
    入驻小区
**/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            partnerPoolInfo: {
                partnerPools: [],
                partnerTypes:[],
                total: 0,
                records: 1,
                moreCondition: false,
                ppId: '',
                conditions: {
                    partnerName: '',
                    partnerType: '',
                    state: '',

                }
            }
        },
        _initMethod: function () {
            $that._loadListPaymentAdapt();
            $that._listPartnerPools(DEFAULT_PAGE, DEFAULT_ROWS);
        },
        _initEvent: function () {

            vc.on('partnerPool', 'listPartnerPool', function (_param) {
                $that._listPartnerPools(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('pagination', 'page_event', function (_currentPage) {
                $that._listPartnerPools(_currentPage, DEFAULT_ROWS);
            });
        },
        methods: {
            _listPartnerPools: function (_page, _rows) {

                $that.partnerPoolInfo.conditions.page = _page;
                $that.partnerPoolInfo.conditions.row = _rows;
                $that.partnerPoolInfo.conditions.shopId = vc.getCurrentCommunity().shopId;
                let param = {
                    params: $that.partnerPoolInfo.conditions
                };

                //发送get请求
                vc.http.apiGet('/partner.listPartnerPool',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        $that.partnerPoolInfo.total = _json.total;
                        $that.partnerPoolInfo.records = _json.records;
                        $that.partnerPoolInfo.partnerPools = _json.data;
                        vc.emit('pagination', 'init', {
                            total: $that.partnerPoolInfo.records,
                            currentPage: _page
                        });
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _openAddPartnerPoolModal: function () {
                vc.emit('addPartnerPool', 'openAddPartnerPoolModal', {});
            },
            _openEditPartnerPoolModel: function (_partnerPool) {
                vc.emit('editPartnerPool', 'openEditPartnerPoolModal', _partnerPool);
            },
            _openDeletePartnerPoolModel: function (_partnerPool) {
                vc.emit('deletePartnerPool', 'openDeletePartnerPoolModal', _partnerPool);
            },
            _queryPartnerPoolMethod: function () {
                $that._listPartnerPools(DEFAULT_PAGE, DEFAULT_ROWS);

            },
            _moreCondition: function () {
                if ($that.partnerPoolInfo.moreCondition) {
                    $that.partnerPoolInfo.moreCondition = false;
                } else {
                    $that.partnerPoolInfo.moreCondition = true;
                }
            },
            _loadListPaymentAdapt:function(){
                let param = {
                    params: {
                        page: 1,
                        row: 100,
                    }
                };
                //发送get请求
                vc.http.apiGet('/partner.listPartnerAdapt', param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        $that.partnerPoolInfo.partnerTypes = _json.data;
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            }


        }
    });
})(window.vc);
